package com.forever7776.life.core.service.impl.sys;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.forever7776.life.core.common.util.ResultVoUtil;
import com.forever7776.life.core.entity.sys.SysFunction;
import com.forever7776.life.core.mapper.sys.SysFunctionMapper;
import com.forever7776.life.core.service.sys.ISysFunctionService;
import com.forever7776.life.remote.common.vo.ResultVO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 菜单表 服务实现类
 * </p>
 *
 * @author kz
 * @since 2018-01-18
 */
@Service
public class SysFunctionServiceImpl extends ServiceImpl<SysFunctionMapper, SysFunction> implements ISysFunctionService {

    /**
     * 根据功能名称查询功能列表
     *
     * @param page
     * @param functionName
     * @return
     */
    @Override
    public Page<SysFunction> selectAll(Page<SysFunction> page, String functionName) {
        return this.selectPage(page, new EntityWrapper<SysFunction>().like("name", functionName).orderBy("sort,last_update", false));
    }

    /**
     * 查询功能列集合
     *
     * @param userId
     * @return
     */
    @Override
    public List<Object> getUrls(String userId) {
        return selectObjs(new EntityWrapper<SysFunction>().eq("user_id", userId).setSqlSelect("url"));
    }

    /**
     * 菜单是否显示
     *
     * @param id
     * @param status
     * @return
     */
    @Override
    public ResultVO frozen(String id, Integer status) {
        SysFunction function = selectById(id);
        if (function == null) {
            return ResultVoUtil.getFailResult("该菜单不存在！");
        }
        function.setStatus(status);
        this.updateById(function);
        return ResultVoUtil.getSuccessResult("操作成功！");
    }
}
